import requests
from lxml import etree
from lxml.etree import HTMLParser
import json
import io
import sys

#改变标准输出的默认编码
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')

def db_music(url):
	'''
	摇滚
	'''
	# proxies = {
	# 	"http": "203.124.53.25:45780",
	# 	"https": "http://75.128.209.158:8080",
	# }
	l_response = requests.get(url)
	body = l_response.text
	dicts = json.loads(body)
	songlist = dicts['songs'][:10]
	item_dict = {}
	item_list = []
	for s in songlist:
		item_dict = {
			'aid':s['aid'],
			'title':s['title'],
			'artist':s['artist'],
			'albumtitle':s['albumtitle'],
			'pub_time':s['public_time'],
			'img_url':s['picture'],
			'url':s['url']
		}
		item_list.append(item_dict)
		
	return item_list

if __name__ == '__main__':
	url = 'https://douban.fm/j/v2/songlist/365774/?kbps=192'
	item_list = db_music(url)
	print(item_list)